package role

import (
	"gin_demo/utility"

	"github.com/gin-gonic/gin"
)

var SRole = sRole{}

type sRole struct{}

//@Summary  后台角色查看接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param Limit query int true "一次性最大页数"
//@Param Page query int true "当前页数"
//@Router  /backend/role/list  [get]
//@version 1.0
func (role *sRole) List(ctx *gin.Context) {
	req := PageList{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		List(ctx, req)
	}
}

//@Summary  后台角色添加接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body role.AddRoleReq{} true "角色添加请求参数"
//@Router  /backend/role/add  [post]
//@version 1.0
func (role *sRole) Create(ctx *gin.Context) {
	req := AddRoleReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Create(ctx, req)
	}
}

//@Summary  后台角色删除接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body role.SoftDeleteReq{} true "角色删除请求参数"
//@Router  /backend/role/del  [delete]
//@version 1.0
func (role *sRole) Delete(ctx *gin.Context) {
	req := SoftDeleteReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Delete(ctx, req)
	}
}

//@Summary  后台角色更新接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body role.UpdateRoleReq{} true "角色更新请求参数"
//@Router  /backend/role/update  [put]
//@version 1.0
func (role *sRole) Update(ctx *gin.Context) {
	req := UpdateRoleReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Update(ctx, req)
	}
}

//@Summary  后台角色权限添加接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body role.RoleAddPermission{} true "后台角色权限添加请求参数"
//@Router  /backend/role/create_role_permission  [post]
//@version 1.0
func (role *sRole) CreadRolePermission(ctx *gin.Context) {
	req := RoleAddPermission{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		CreadRolePermission(ctx, req)
	}
}

//@Summary  后台角色权限删除接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body role.RoleSoftDeletePermission{} true "后台角色权限删除请求参数"
//@Router  /backend/role/del_role_permission  [delete]
//@version 1.0
func (role *sRole) DeleteRolePermission(ctx *gin.Context) {
	req := RoleSoftDeletePermission{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		DeleteRolePermission(ctx, req)
	}
}

//@Summary  后台角色权限查看接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param Limit query int true "一次性最大页数"
//@Param Page query int true "当前页数"
//@Router  /backend/role/role_permission  [get]
//@version 1.0
func (role *sRole) RolePermission(ctx *gin.Context) {
	req := PageList{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		RolePermission(ctx, req)
	}
}

//@Summary  后台角色权限更新接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body role.RoleUpdatePermission{} true "后台角色权限更新请求参数"
//@Router  /backend/role/updaterolepermission  [put]
//@version 1.0
func (role *sRole) UpdateRolePermission(ctx *gin.Context) {
	req := RoleUpdatePermission{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		UpdateRolePermission(ctx, req)
	}
}
